package com.xiaoxi.xiojcodesandbox.security;

import java.security.Permission;

/**
 *  自定义安全管理器
 */
public class MySecurityManager extends SecurityManager{

    /**
     *  限制所有操作
     * @param perm   the requested permission.
     */
    @Override
    public void checkPermission(Permission perm) {
    }

    /**
     *  限制读操作
     * @param file   the system-dependent file name.
     */
    @Override
    public void checkRead(String file) {
        if (file.contains("application")){
            throw new SecurityException("checkRead异常:" + file);
        }
    }

    /**
     *  限制写操作
     * @param file   the system-dependent filename.
     */
    @Override
    public void checkWrite(String file) {
        throw new SecurityException("checkWrite异常:" + file);
    }

    /**
     *  限制删除操作
     * @param file   the system-dependent filename.
     */
    @Override
    public void checkDelete(String file) {
//        super.checkDelete(file);
    }

    /**
     *  限制访问网络
     * @param host   the host name port to connect to.
     * @param port   the protocol port to connect to.
     */
    @Override
    public void checkConnect(String host, int port) {
//        if (!host.equals("127.0.0.1") && !host.equals("localhost")){
//            throw new SecurityException("checkConnect异常:" + host + ":" + port);
//        }
    }
}
